package b_threadAPI;


public class ThreadAPIDemo02 {
    public static void main(String[] args) {
        //一个任务类,可以供多个线程使用
        Runnable r = new Runnable() {
            @Override
            public void run() {
                for (int i = 0; i < 10; i++) {
                    //获取当前线程
                    Thread t = Thread.currentThread();
                    //获取当前线程名称
                    String name = t.getName();
                    System.out.println("当前线程名字:" + name + ": " +i);
                }
            }
        };

        //创建线程对象
        Thread t1 = new Thread(r, "小明");
        Thread t2 = new Thread(r, "小红");

        t1.start();
        t2.start();

    }
}
